// 包裹Row
export function wrapRowToken(str) {
  return `
    <a-row v-bind="layoutConfig.row">
${str}    </a-row>`;
}

export function appendRowStartToken(str) {
  return `${str}
  <a-row v-bind="layoutConfig.row">
`;
}

export function appendRowEndToken(str) {
  return `${str}
  </a-row>`;
}

// 包裹Col
export function wrapColToken(str) {
  return `      <a-col v-bind="layoutConfig.col">
${str}
      </a-col>
`;
}

// 包裹form-item
export function wrapFormItemToken(str, formField) {
  const { formKey } = formField;
 const formKeyArr = formKey.split(".");
  const isSubForm = formKeyArr.length > 2;
  let propStr = "";
  if (isSubForm) {
    propStr = `:prop="\${formKey}"`;
  } else {
    propStr = `label="${formField.label}" prop="${formKey}"`;
  }
  return `        <a-form-item ${propStr}>
${str}
        </a-form-item>`;
}

// 包裹readonly
export function wrapReadonlyToken(str, formField) {
  const displayKey = formField.displayKey ?? formField.formKey;
  return `          <readonly-field
            :isPreview="isPreview"
            :displayText="formData.${displayKey}"
          >
            ${str}
          </readonly-field>`;
}

// 包裹search-form
export function wrapSearchFormToken(str) {
  return `<a-form layout="inline" :form="queryFormData" class="search-form">
            ${str}
            <a-form-item>
              <a-button type="primary" @click="handleSearch">
                查询
              </a-button>
              <a-button @click="handleReset">
                重置
              </a-button>
            </a-form-item>
          </a-form>`;
}


// 包裹subFrom column
export function wrapSubFormTableColumnToken( str,
  formField,
  isSubFormTableData) {
  let scopeStr = "";
  let scopeData = "$index";
  if (formField.label === "序号") {

  } else if (formField.label === "操作") {
    scopeStr = `<a-button type="text" @click="handleDelete($index)"> 删除 </a-button>`;
  } else {
    scopeData = "row,$index";
    scopeStr = str;
  }

  return `<a-table-column
          label="${formField.label}"
          ${formField.label === "序号" ? 'width="60px"' : ""}
        >
          <template #default="{${scopeData}}">
            ${scopeStr}
          </template>
        </a-table-column>
`;
}

// 包裹纯文本
export function wrapFieldTextToken(formField) {
   const { type } = formField;
  if (type === "preview-media") {
    return `<PreviewMedia :fileList="formData.${formField.formKey}" />`;
  } else if (type === "upload-file") {
    return `<UploadFile disabled v-model="formData.${formField.formKey}" />`;
  }
  return `<ReadonlyField isPreview :displayText="formData.${formField.formKey}"/>`;
}

// ========== 根据项目自定义 ============

// 包裹groupForm
export function wrapGroupFormWrapToken(str, formField) {
  return `
<a-card title="${formField.label}" style="width: 300px">
   ${str} 
</a-card>
`;
}
// 包裹subForm table
export function wrapSubFormTableToken(str, formField) {
  return `<a-table
          :data-source="formData.${formField.formKey}"
          style="width: 100%"
        >
          ${str}
        </a-table>`;
}